package com.alangyun.remind.controller;

import org.springframework.ui.Model;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.alangyun.remind.BaseActor;
import com.alangyun.remind.RemindPreference;
import com.alangyun.remind.error.MindException;

public abstract class AbstractController extends BaseActor {
	private static final String ERROR = "error";

	protected String pageError(Model model,String error) {
		model.addAttribute(ERROR, ErrorMessage.create(error));
		return "/mind/page-error";
	}
	
	protected String pageError(Model model,int step, String error) {
		model.addAttribute(ERROR, ErrorMessage.create(step, error));
		return "/mind/page-error";
	}
	
	protected String pageError(RedirectAttributes model,String error) {
		model.addFlashAttribute(ERROR, ErrorMessage.create(error));
		return Paths.redirectError();
	}
	
	protected String pageError(RedirectAttributes model,int step, String error) {
		model.addFlashAttribute(ERROR, ErrorMessage.create(step, error));
		return Paths.redirectError();
	}
	
	protected void validateTimeout() {
		if(!RemindPreference.isNormal())
			throw new MindException("系统版本无法验证，可能已过失效期或者为测试版本！");
	}
}
